import axios from 'axios'
import { message } from 'ant-design-vue'
import { stringify } from "qs"
// import store from '@/store'

const base_url: string = process.env.NODE_ENV === 'development' ? '/skyApi' : (import.meta.env.VITE_APP_API_BASE_URL_2) as string

// create an axios instance
const service = axios.create({
    baseURL: base_url,
    timeout: 5000,
    withCredentials: true,
})

// request interceptor
service.interceptors.request.use(
    config => {
        if (config.method === 'post') {
            config.data = stringify(config.data)
        }
        return config
    },
    error => {
        Promise.reject(error)
    }
)

// response interceptor
service.interceptors.response.use(
    response => {
        const res = response.data
        return response.data
        // if (res.code !== 0) {
        //     message.warning(res.msg);
        //     return Promise.reject('error')
        // } else {
        //     return response.data
        // }
    },
    error => {
        message.warning(error.message);
        return Promise.reject(error)
    }
)

export default service